package com.easyadmin.modules.stock.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easyadmin.common.web.domain.request.PageDomain;
import com.easyadmin.modules.stock.domain.*;
import com.easyadmin.modules.stock.mapper.SysStockMessageDao;
import com.easyadmin.modules.stock.service.SysStockMessageServer;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("sysStockMessageServer")
public class SysStockMessageServerImpl extends ServiceImpl<SysStockMessageDao, SysStockMessage>
        implements SysStockMessageServer {


    @Autowired
    SysStockMessageDao sysStockMessageDao;

    @Override
    public PageInfo<SysStockMessage> queryPage(SysStockMessage sysStockMessage, PageDomain pageDomain) {
        PageHelper.startPage(pageDomain.getPage(), pageDomain.getLimit());
        List<SysStockMessage> data =sysStockMessageDao.selectList(new QueryWrapper<SysStockMessage>().lambda()
                .like(StringUtils.isNotBlank(sysStockMessage.getMessageName()),
                        SysStockMessage::getMessageName,sysStockMessage.getMessageName())
                .like(StringUtils.isNotBlank(sysStockMessage.getMessageDesc()),
                        SysStockMessage::getMessageDesc,sysStockMessage.getMessageDesc())
                .eq(StringUtils.isNotBlank(sysStockMessage.getImporFlag()),
                        SysStockMessage::getImporFlag,sysStockMessage.getImporFlag())
                .orderBy(true,false, SysStockMessage::getMessageTime));
        return new PageInfo<>(data);
    }


    /**
     * Describe: 根据 id 删除某条数据
     * Param: id
     * Return: Boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean remove(String id) {
        sysStockMessageDao.deleteById(Integer.valueOf(id));
        return true;
    }



    /**
     * Describe: 修改用户数据
     * Param: SysUser
     * Return: 操作结果
     */
    @Override
    public boolean update(SysStockMessage sysFactorEntity) {
        Integer result = sysStockMessageDao.updateById(sysFactorEntity);
        return result > 0;
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchRemove(String[] ids) {
        for(String  id:ids){
            sysStockMessageDao.deleteById(id);
        }
        return true;
    }
}
